package com.insta.adapterList;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.insta.playdroid.R;
import com.insta.playdroid.metier.domain.Song;

public class SongAdapter extends BaseAdapter {

	private List<Song> songs = new ArrayList<Song>();
	private LayoutInflater layoutInflater;

	public SongAdapter(Context context, List<Song> allSong) {

		layoutInflater = LayoutInflater.from(context);

		this.songs = allSong;
	}

	private class ViewHolder {

		TextView songtxt;
		TextView songdetailtxt;

	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder;

		if (convertView == null) {

			holder = new ViewHolder();

			convertView = layoutInflater.inflate(R.layout.songitem, null);

			holder.songtxt = (TextView) convertView.findViewById(R.id.itemsong);
			holder.songdetailtxt = (TextView) convertView
					.findViewById(R.id.itemsongdetail);

			convertView.setTag(holder);

		} else {

			holder = (ViewHolder) convertView.getTag();

		}

		holder.songtxt.setText(songs.get(position).getTitle());

		holder.songdetailtxt.setText(songs.get(position).getArtist() + "\n"
				+ songs.get(position).getAlbum());

		return convertView;
	}

	@Override
	public int getCount() {
		return songs.size();
	}

	@Override
	public Object getItem(int pos) {
		return songs.get(pos);
	}

	@Override
	public long getItemId(int pos) {
		return pos;
	}

	public List<Song> getSongs() {
		return songs;
	}

	public void setSongs(List<Song> songs) {
		this.songs = songs;
	}

	public LayoutInflater getLayoutInflater() {
		return layoutInflater;
	}

	public void setLayoutInflater(LayoutInflater layoutInflater) {
		this.layoutInflater = layoutInflater;
	}

}
